package com.zsyh.jiujiu.bean;



import com.zsyh.jiujiu.BuildConfig;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitWuliu {


    private final String TAG = "RetrofitHelper";
    private static RetrofitWuliu INSTANCE;
    private final int REQUEST_TIME_OUT = 5;
    public String debugUrl = "http://v.juhe.cn/exp/";
    public String releaseUrl = "http://v.juhe.cn/exp/";
    private Retrofit mRetrofit;
    private OkHttpClient mOkHttpClient;
    private RetrofitWuliu() {
        mOkHttpClient = new OkHttpClient.Builder()
                .retryOnConnectionFailure(true)
                .connectTimeout(REQUEST_TIME_OUT, TimeUnit.SECONDS)
                .readTimeout(REQUEST_TIME_OUT, TimeUnit.SECONDS)
                .writeTimeout(REQUEST_TIME_OUT, TimeUnit.SECONDS).build();
        mRetrofit = new Retrofit.Builder()
                .client(mOkHttpClient)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .baseUrl(BuildConfig.DEBUG ? debugUrl : releaseUrl)
                .build();
    }

    public static RetrofitWuliu getInstance() {
        if (INSTANCE == null) {
            synchronized (RetrofitWuliu.class) {
                if (INSTANCE == null) {
                    INSTANCE = new RetrofitWuliu();
                }
            }
        }
        return INSTANCE;
    }

    /**
     * 使用原来的baseUrl
     * @return
     */
    public Retrofit getRetrofit() {
        return mRetrofit;
    }



}
